package com.woniu.tank.tank;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;

import javax.swing.JPanel;

import com.woniu.tank.bullet.GoodBullet;
import com.woniu.tank.ui.GamePanel;



public class GoodTank extends Tank {

	//绘制自己的好坦克
	public void drawGoodtank(Graphics g ,Image tank, JPanel p ,Image image){
		g.drawImage(tank, x<<5, y<<5, (x+1)<<5, (y+1)<<5, step*28, dir*28,(step+1)*28 , (dir+1)*28, p);	
		super.step();
		super.underGrass(g, p, image);
	}
	//开火
	public GoodBullet fir(){
		if(!live) return null;
		GoodBullet gb = new GoodBullet(x, y, dir, tc);
		GamePanel.gbbullet.add(gb);
		return gb;		
	}
	//坦克移动
	public void move(KeyEvent e, int[][] map) {
		// TODO Auto-generated method stub
		switch(e.getKeyCode()){			
		case KeyEvent.VK_J:
			//调用坦克开火
			fir();
			break;
		case KeyEvent.VK_W:
			if(dir !=0){
				dir=0;
			}
			else if(map[y-1][x]== 0 || map [y-1][x] ==3 ){
				y--;
			}
			break;
		case KeyEvent.VK_S:

			if(dir !=2){
				dir=2;
			}
			else if(map[y+1][x]==0 || map [y+1][x] ==3 ){
				y++;
			}
			break;
		case KeyEvent.VK_A:
			if(dir !=3){
				dir=3;
			}
			else if(map[y][x-1]==0 || map [y][x-1] ==3 )	{			
				x--;		
			}
			break;
		case KeyEvent.VK_D:
			if(dir !=1){
				dir = 1;
			}
			else if(map[y][x+1]==0 || map [y][x+1] ==3 ){
				x++;
			}		
		}

	}
	public GoodTank() {
		super();
	}

	public GoodTank(int x, int y,GamePanel tc) {
		super(x, y,tc);		
	}
}


